package com.lyj.controller;


import com.lyj.pojo.Result;
import com.lyj.pojo.dto.UserUpdateDTO;
import com.lyj.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2025-10-10
 * Time: 23:14
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;

    @PostMapping("/login")
    public Result login(String username, String password){
        return Result.success(userService.login(username,password));
    }
    // 新增注册接口
    @PostMapping("/register")
    public Result register(String username, String password, String invitationCode) {
        Integer userId = userService.register(username, password, invitationCode);
        return Result.success(userId);
    }
    @PutMapping("/update-profile")
    public Result updateUserProfile(@Valid @RequestBody UserUpdateDTO userUpdateDTO) {
        userService.updateUserProfile(userUpdateDTO);
        return Result.success("用户信息更新成功");
    }
}
